<template>
	<view class="good-list-item" :class="{'show-style': showRadio}">
		<radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioClickHandler"></radio>
		<view class="img" :style="{'margin-left': showRadio ? '10px' : '0px'}">
			<image :src="goods.goods_small_logo || defaultPic"></image>
		</view>
		<view class="info">
			<text class="name">{{ goods.goods_name }}</text>
			<view class="price-num">
				<text class="price">￥ {{ goods.goods_price | tofixed }}</text>
				<uni-number-box v-if="showRadio" :min="1" :value="goods.goods_count" @change="numClickHandler" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		// 过滤器处理价格展示两位小数
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			radioClickHandler() {
				this.$emit('radioChange', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			numClickHandler(v) {
				this.$emit('numChange', {
					goods_id: this.goods.goods_id,
					goods_count: +v // 数字
				})
			}
		}
	}
</script>

<style lang="scss">
.good-list-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px;
	.img {
		margin-right: 10px;
		image {
			width: 100px;
			height: 100px;
		}
	}
	.info {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 100px;
		width: 67%;
		.name {
			font-size: 12px;
		}
		.price-num {
			display: flex;
			justify-content: space-between;
			.price {
				color: red;
			}
		}
	}
}
.show-style {
	background-color: #fff;
	margin: 5px 0 0;
}
</style>